using System;
using GameFramework;
using UnityEngine;

namespace LS
{
    public abstract class ProxyVariable : Variable
    {
        public event EventHandler<ProxyVariable> OnValueChanged;
        public event EventHandler<ProxyVariable> OnVariableRelease;

        protected string name;
        public string Name
        {
            get { return name; }
        }
        
        public virtual void SetName(string name)
        {
            this.name = name;
        }
    }
    
    public class ProxyVariable<T> : ProxyVariable
    {
        public static readonly Type ValueType = typeof(T);
        
        protected T value;

        public T Value
        {
            get { return value; }
        }
        
        public override Type Type => ValueType;


        
        public override object GetValue()
        {
            return GetValueData();
        }

        public override void SetValue(object value)
        {
            SetValueData((T)value);
        }

        public virtual void SetValueWithoutEvent(object value)
        {
            SetValueData((T)value);
        }
        
        public virtual T GetValueData()
        {
            return value;
        }

        public virtual void SetValueData(T value)
        {
            if (this.value != null && !this.value.Equals(value))
            {
                this.value = value;
            }
            else if (value != null)
            {
                
            }
        }
        
        public override void Clear()
        {
            
        }
    }
}
